#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstdint>

using namespace std;

class Solution {
public:
    string longestCommonPrefix(vector<string>& strs) {
        string pub;
        int minLength = 0xFFFF;
        if (0 == strs.size()) return pub;
        for(int i = 0; i < strs.size(); i++){
            if (strs[i].length() < minLength){
                minLength = strs[i].length();
            }
        }
        int j;
        for (int i = 0; i < minLength; i++){
            char now = strs[0][i];
            int flag = 0;
            for (j = 0; j < strs.size(); j++){
                if (now != strs[j][i]){
                    flag = 1;
                    break;
                }
            }
            if (!flag){
                pub += now;
            }else{
                break;
            }
        }
        return pub;
    }
};

int main(void)
{
    Solution su;
    vector<string> vec = {"aca", "cba"};
    string result = su.longestCommonPrefix(vec);
    cout << result << endl;
    return 0;
}
